home *** CD-ROM | disk | FTP | other *** search
- unit Unit1;
- //
- // Test unit for the simple singleton in HVTimeKeeper
- //
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- Memo: TMemo;
- Button3: TButton;
- GroupBox1: TGroupBox;
- Button2: TButton;
- Button1: TButton;
- procedure FormCreate(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure Button3Click(Sender: TObject);
- private
- { Private declarations }
- procedure PollInfo;
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- uses
- HVTimeKeeper;
-
- // Remove the '.' to test that the statements below will not compile
- {.$DEFINE COMPILE_ERRORS_TEST}
- procedure TForm1.FormCreate(Sender: TObject);
- {$IFDEF COMPILE_ERRORS_TEST}
- var
- MyTimeKeeper: TTimeKeeper;
- {$ENDIF}
- begin
- {$IFDEF COMPILE_ERRORS_TEST}
- TimeKeeper := nil; // Will not compile
- MyTimeKeeper := TTimeKeeper.Create; // Will not compile
- TimeKeeper.Free; // Will not compile
- TimeKeeper.Destroy; // Will not compile
- {$ENDIF}
- PollInfo;
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- TObject(TimeKeeper).Destroy; // Will compile, but raises exception at runtime
- end;
-
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- TObject(TimeKeeper).Free; // Will compile, but raises exception at runtime
- end;
-
- procedure TForm1.Button3Click(Sender: TObject);
- begin
- PollInfo;
- end;
-
- procedure TForm1.PollInfo;
- begin
- Memo.Lines.Add('Current Date and Time is ' + DateTimeToStr(TimeKeeper.Now));
- end;
-
- end.
-